﻿@using Lib.core;
@using Lib.helper;

@using Bll;
@using Model;
@using Lib.model;
@using WebLogic.Bll.User;
@using WebLogic.Model.User;
@using Model.User;
@using Hiwjcn.Web.Models.Permission;
@{
    Layout = null;

    var model = ViewData["model"] as UserRoleViewModel;
    if (model == null) { model = new UserRoleViewModel(); }
    if (model.User == null) { model.User = new UserModel(); }
}

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!-- header page -->
    @Html.Partial(IncludePath("header"))
</head>

<body>
    @Html.Partial(IncludePath("body_top"))
    @Html.Partial(IncludePath("manage_nav"))


    <div class="container">

        <div class="row">
            <div class="col-md-4">
                @{
                    if (ValidateHelper.IsPlumpList(model.AssignedList))
                    {
                        <div class="box">
                            <h3 class="web_color">已经分配的权限</h3>
                        </div>
                        <div class="list-group" id="assigned_menu">
                            @foreach (var role in model.AssignedList)
                            {
                                <a class="list-group-item" data-id="@(role.RoleID)" href="javascript:;" target="_blank">
                                    <h4 class="list-group-item-heading">@(role.RoleName)</h4>
                                    <p class="list-group-item-text">@(role.RoleDescription)</p>
                                </a>
                            }
                        </div>
                    }
                    else
                    {
                        <div class="alert alert-success">没有任何权限</div>
                    }
                }
            </div>
            <div class="col-md-4">
                <div class="box">
                    @{
                        <div class="col-md-3">
                            <span class="label">当前用户：</span>
                        </div>
                        <div class="col-md-3">@(model.User.NickName)</div>
                    }
                </div>
                <div class="center" style="font-size:100px;padding:80px 0;">
                    <span class="fa fa-arrows-h"></span>
                </div>
            </div>
            <div class="col-md-4">
                @{
                    if (ValidateHelper.IsPlumpList(model.UnAssignedList))
                    {
                        <div class="box">
                            <h3 class="web_color">未分配的权限</h3>
                        </div>
                        <div class="list-group" id="unassigned_menu">
                            @foreach (var role in model.UnAssignedList)
                            {
                                <a class="list-group-item" data-id="@(role.RoleID)" href="javascript:;" target="_blank">
                                    <h4 class="list-group-item-heading">@(role.RoleName)</h4>
                                    <p class="list-group-item-text">@(role.RoleDescription)</p>
                                </a>
                            }
                        </div>
                    }
                    else
                    {
                        <div class="alert alert-success">没有可用的权限</div>
                    }
                }
            </div>
        </div>

    </div>

    <script type="text/javascript">
        $(function () {
            function Assign(id, action) {
                if (!confirm(action == 'add' ? '确定添加此角色？' : '确定删除此角色？')) {
                    return false;
                }
                postJson('/admin/permission/userroleaction/', {
                    action: action,
                    role_id: id,
                    user_id: '@(model.User.UserID)'
                }, function (res) {
                    if (res && res.success) {
                        alert('操作成功');
                        window.location.reload();
                    }
                    else {
                        alert(res.msg);
                    }
                });
            }
            $('#assigned_menu').find('.list-group-item').click(function () {
                var id = $(this).attr('data-id');
                Assign(id, 'del');
            });
            $('#unassigned_menu').find('.list-group-item').click(function () {
                var id = $(this).attr('data-id');
                Assign(id, 'add');
            });
        });
    </script>
    <!-- footer page -->
    @Html.Partial(IncludePath("body_bottom"))
</body>
</html>
